// pages/teacher/home/home.js
const app = getApp()
import { courses } from '../../../utils/mockData.js'

Page({
  data: {
    userInfo: {
      name: '张老师',
      avatar: '/images/teacher1.jpg',
      level: '高级讲师',
      isVerified: true
    },
    // 统计数据
    stats: {
      totalStudents: 856,
      totalRevenue: 15230,
      todayClasses: 2
    },
    // 正在直播的课程
    liveCourses: [
      {
        id: 1,
        title: '微信小程序开发实战',
        coverImage: '/images/course1.jpg',
        viewerCount: 128,
        startTime: '19:00'
      }
    ],
    // 今日课程
    todayClasses: [
      {
        id: 1,
        time: '19:00',
        title: '微信小程序开发实战',
        studentCount: 456,
        status: 'upcoming'
      },
      {
        id: 2,
        time: '19:00',
        title: 'UI/UX设计精品课',
        studentCount: 380,
        status: 'live'
      }
    ],
    // 待处理事项
    todoList: [
      { icon: '📝', text: '待批改作业', count: 12, url: '/pages/teacher/homework/homework' },
      { icon: '💬', text: '待回复问题', count: 8, url: '' },
      { icon: '📊', text: '待审核课程', count: 3, url: '/pages/teacher/course-manage/course-manage' }
    ],
    // 快捷功能
    quickActions: [
      { icon: '➕', text: '发布作业', color: '#667eea', url: '/pages/teacher/homework-create/homework-create' },
      { icon: '📚', text: '试题库', color: '#f093fb', url: '/pages/teacher/question-bank/question-bank' },
      { icon: '📊', text: '学情分析', color: '#4facfe', url: '/pages/teacher/student-data/student-data' },
      { icon: '💰', text: '收益统计', color: '#43e97b', url: '/pages/teacher/revenue/revenue' }
    ]
  },
  onLoad() {
    this.loadUserInfo()
    this.loadData()
  },
  onShow() {
    this.loadData()
  },
  onPullDownRefresh() {
    this.loadData()
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 1000)
  },
  loadUserInfo() {
    const userInfo = wx.getStorageSync('userInfo')
    if (userInfo) {
      this.setData({ userInfo })
    }
  },
  loadData() {
    // 模拟加载数据
    // 实际项目中这里应该调用 API
  },
  goToLiveRoom(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/teacher/live-room/live-room?courseId=${id}`
    })
  },
  goToPage(e) {
    const url = e.currentTarget.dataset.url
    if (url) {
      wx.navigateTo({ url })
    } else {
      wx.showToast({
        title: '功能开发中',
        icon: 'none'
      })
    }
  },
  goToCourseManage() {
    wx.navigateTo({
      url: '/pages/teacher/course-manage/course-manage'
    })
  },
  goToHomework() {
    wx.navigateTo({
      url: '/pages/teacher/homework/homework'
    })
  },
  createCourse() {
    wx.navigateTo({
      url: '/pages/teacher/course-manage/course-manage?action=create'
    })
  },
  goToProfile() {
    wx.navigateTo({
      url: '/pages/teacher/profile/profile'
    })
  }
})
